package com.esri.core.tasks.na;

import com.esri.core.internal.tasks.d.d;
import com.esri.core.io.UserCredentials;
import java.util.List;

/* loaded from: classes.dex */
class OnlineRouteTask extends RouteTask {
    String _url;
    UserCredentials credentials;
    private long mAttributeHelper = 0;
    private NetworkDescription mDescription = null;

    public OnlineRouteTask(String str) {
        this._url = str;
    }

    public OnlineRouteTask(String str, UserCredentials userCredentials) {
        this._url = str;
        this.credentials = userCredentials != null ? userCredentials.getCopy() : null;
    }

    @Override // com.esri.core.tasks.na.RouteTask
    public RouteParameters retrieveDefaultRouteTaskParameters() throws Exception {
        d dVar = new d(null, this._url, this.credentials);
        OnlineRouteParameters onlineRouteParameters = new OnlineRouteParameters();
        onlineRouteParameters._params = dVar.a();
        if (this.mDescription == null) {
            this.mDescription = getNetworkDescription();
        }
        return onlineRouteParameters;
    }

    @Override // com.esri.core.tasks.na.RouteTask
    public RouteResult solve(RouteParameters routeParameters) throws Exception {
        String[] strArr = new String[3];
        double[] dArr = {1.0d, 1.0d, 1.0d};
        String[] augmentAttributes = LocalRouteTask.augmentAttributes(this.mAttributeHelper, routeParameters.getImpedanceAttributeName(), routeParameters.getAccumulateAttributeNames(), strArr, dArr);
        if (strArr[0] != null && augmentAttributes != null) {
            routeParameters.setImpedanceAttributeName(strArr[0]);
            routeParameters.setAccumulateAttributeNames(augmentAttributes);
            ((OnlineRouteParameters) routeParameters).setDirectionsTimeAttributeName(strArr[1]);
        }
        RouteResult execute = new d(((OnlineRouteParameters) routeParameters).getParams(), this._url, this.credentials).execute();
        execute.updateConvenience(strArr[1], strArr[2], dArr[0], dArr[1], dArr[2]);
        return execute;
    }

    @Override // com.esri.core.tasks.na.RouteTask
    public NetworkDescription getNetworkDescription() throws Exception {
        NetworkDescription networkDescription = this.mDescription;
        if (networkDescription != null) {
            return networkDescription;
        }
        NetworkDescription c = new d(null, this._url, this.credentials).c();
        this.mDescription = c;
        List<CostAttribute> costAttributes = c.getCostAttributes();
        String[] strArr = new String[costAttributes.size()];
        String[] strArr2 = new String[costAttributes.size()];
        for (int i = 0; i < costAttributes.size(); i++) {
            strArr[i] = costAttributes.get(i).getName();
            strArr2[i] = costAttributes.get(i).getUnits().name();
        }
        this.mAttributeHelper = LocalRouteTask.createAttributeHelper(0L, strArr, strArr2, this.mDescription.mDefaultImpedance, (String[]) this.mDescription.mDefaultAccumulates.toArray(new String[this.mDescription.mDefaultAccumulates.size()]), this.mDescription.mDefaultDirectionsTimeAttribute);
        return c;
    }

    protected void finalize() throws Throwable {
        LocalRouteTask.releaseAttributeHelper(this.mAttributeHelper);
        this.mAttributeHelper = 0L;
        super.finalize();
    }
}
